package com.toweave.starter.utils;

import android.os.Handler;
import android.os.Looper;

public class UiThreadUtil {
  private static final Handler handler = new Handler(Looper.getMainLooper());

  public static void runOnUiThread(Runnable runnable) {
    if (Looper.myLooper() == Looper.getMainLooper()) {
      // 当前线程就是UI线程
      runnable.run();
    } else {
      // 如果当前线程不是UI线程，将任务投递到UI线程的消息队列中
      handler.post(runnable);
    }
  }
}
